import Vue from "vue";
import App from "./App.vue";
import VueCropper from "vue-cropper";
import VueLazyload from "vue-lazyload";//可以用v-lazy对图片进行懒加载！！！
import router from "@/router";
import store from "@/store";
import "@/plugins/my-element";
import "@/utils/filters";
import "@/assets/css/global.css";
import "@/assets/css/my-element.css";
import "@/assets/css/btn.css";

// with options
Vue.use(VueCropper);
Vue.use(VueLazyload, {
  preLoad: 1.9,
  error: require("./assets/img/error.jpg"),
  loading: require("./assets/img/loading.gif"),
  attempt: 3,
});

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: (h) => h(App),
  created() {
    // 有关浏览器类型的信息都藏在USER-AGENT里面，首先读取navigator.userAgent里面的信息，为了方便利用toLowerCase方法转成小写的形式
    const sUserAgent = navigator.userAgent.toLowerCase();
    const bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    const bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    const bIsMidp = sUserAgent.match(/midp/i) == "midp";
    const bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    const bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    const bIsAndroid = sUserAgent.match(/android/i) == "android";
    const bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    const bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    //如果匹配上面的浏览器就跳转打开移动端页面
    if (
      bIsIpad ||
      bIsIphoneOs ||
      bIsMidp ||
      bIsUc7 ||
      bIsUc ||
      bIsAndroid ||
      bIsCE ||
      bIsWM
    ) {
      //如果是移动端就跳转打开移动端页面
      this.$store.commit("setIsPhone", true);
    } else {
      //Pc端进入不需要其他操作
      this.$store.commit("setIsPhone", false);
    }
  },
  beforeCreate(){//定义全局事件总线
    // 利用Vue实例的原型链，在根实例中创建一个事件总线，并使其成为全局可访问的。
    Vue.prototype.$bus = this;
  }
}).$mount("#app");
